#include<bits/stdc++.h>
using namespace std;
template <typename T>void read(T &x){
    int f=1;x=0;char c=getchar();
    for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    x*=f;
}
const int maxn=1e5+5;
int T,n,a[maxn];

int dfs(int x,int col,int lst,int ans){
    int y0,y1;
    if(x==n+1)return ans;
    // red
    if(col==0){
        return max(dfs(x+1,0,lst,ans+((a[x-1]==a[x])?a[x]:0)),dfs(x+1,1,x-1,ans+((a[lst]==a[x])?a[x]:0)));
    }
    if(col==1)return max(dfs(x+1,1,lst,ans+((a[x-1]==a[x])?a[x]:0)),dfs(x+1,0,x-1,ans+((a[lst]==a[x])?a[x]:0)));
    //return max(y0,y1);
}

int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    read(T);
    while(T--){
        read(n);
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)read(a[i]);
        int ans0=dfs(2,0,0,0);//red 0
        int ans1=dfs(2,1,0,0);//blue 1
        cout<<max(ans0,ans1)<<endl;
    }
    return 0;
}
